package com.wu.ssm.config;

import com.wu.ssm.controller.SimpleServlet;
import com.wu.ssm.spring.mvc.MyDispatcherServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by wzf on 2018/11/4/004.
 */

@Configuration
public class ServletConfig {
    @Bean
    public ServletRegistrationBean dispatcherRegistration() {
        MyDispatcherServlet dispatcherServlet = new MyDispatcherServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(dispatcherServlet,"/*");
        registrationBean.setLoadOnStartup(1);
        registrationBean.setName("dispatcherServlet");
        return registrationBean;
    }

    @Bean
    public ServletRegistrationBean simpleServletRegistration() {
        SimpleServlet simpleServlet = new SimpleServlet();

        ServletRegistrationBean registrationBean = new ServletRegistrationBean(simpleServlet,"/simpleServlet");
        registrationBean.setLoadOnStartup(0);
        registrationBean.setName("simpleServlet");//因为name相同的ServletRegistrationBean只有一个会生效，也就是说，后注册的会覆盖掉name相同的ServletRegistrationBean。
        return registrationBean;
    }
}
